require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("../../assets/fonts/iconfont.css");
require("../../assets/css/tabbar.less");
require("./mine.css");

// 引入js模块
const dom = require("../../utils/dom.js");

// 引入axios
const axios = require("axios");

document.addEventListener("DOMContentLoaded", function () {
	// 渲染tabber
	dom.tabbar("mine");

	//跳转运动数据详情页
	dom.get("#sports-data").addEventListener("click", function () {
		location.href = "mine_sports_data.html";
	});
	// 发送请求获取用户信息
	axios.defaults.baseURL = "http://fitness.h5.itsource.cn:3701";
	let token = localStorage.getItem("token");
	axios.defaults.headers.common["Authorization"] = "Bearer " + token;
	axios.get("/api/user/info").then((res) => {
		console.log(res);
		dom.get("#nickName").textContent = res.data.data.nickName;
		dom.get("#photo").src = axios.defaults.baseURL + res.data.data.imgUrl;
		dom.get("#sign").textContent = res.data.data.sign;
		dom.get("#duration").textContent = res.data.data.duration;
		dom.get("#calorieNum").textContent = res.data.data.calorie;
	});

	// 修改个人信息
	dom.get("#photo").addEventListener("click", function () {
		location.href = "../mine_modify.html";
	});

	// 发送请求获取用户徽章
	// axios.get("/api/exercise/badge").then((res) => {
	// 	console.log(res);
	// });
});
